home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Python 1.3.3 / Python 133 SRC / Mac / Modules / win / winscan.py < prev    next >
Text File  |  1996-04-12  |  2KB  |  77 lines

  1. # Scan an Apple header file, generating a Python file of generator calls.
  2. import addpack
  3. addpack.addpack(':Tools:bgen:bgen')
  4. from bgenlocations import TOOLBOXDIR
  5.  
  6. from scantools import Scanner
  7.  
  8. def main():
  9.     input = "Windows.h"
  10.     output = "wingen.py"
  11.     defsoutput = TOOLBOXDIR + "Windows.py"
  12.     scanner = MyScanner(input, output, defsoutput)
  13.     scanner.scan()
  14.     scanner.close()
  15.     print "=== Done scanning and generating, now importing the generated code... ==="
  16.     import winsupport
  17.     print "=== Done.  It's up to you to compile it now! ==="
  18.  
  19. class MyScanner(Scanner):
  20.  
  21.     def destination(self, type, name, arglist):
  22.         classname = "Function"
  23.         listname = "functions"
  24.         if arglist:
  25.             t, n, m = arglist[0]
  26.             if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode":
  27.                 classname = "Method"
  28.                 listname = "methods"
  29.         return classname, listname
  30.  
  31.     def makeblacklistnames(self):
  32.         return [
  33.             'DisposeWindow', # Implied when the object is deleted
  34.             'CloseWindow',
  35.             ]
  36.  
  37.     def makeblacklisttypes(self):
  38.         return [
  39.             'ProcPtr',
  40.             'WCTabHandle',
  41.             'AuxWinHandle',
  42.             'PixPatHandle',
  43.             'DragGrayRgnUPP',
  44.             ]
  45.  
  46.     def makerepairinstructions(self):
  47.         return [
  48.             
  49.             # GetWTitle
  50.             ([("Str255", "*", "InMode")],
  51.              [("*", "*", "OutMode")]),
  52.             
  53.             ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
  54.              [("InBuffer", "*", "*")]),
  55.             
  56.             ([("void", "*", "OutMode"), ("long", "*", "InMode"),
  57.                                         ("long", "*", "OutMode")],
  58.              [("VarVarOutBuffer", "*", "InOutMode")]),
  59.             
  60.             ([("void", "wStorage", "OutMode")],
  61.              [("NullStorage", "*", "InMode")]),
  62.             
  63.             ([("WindowPtr", "*", "OutMode")],
  64.              [("ExistingWindowPtr", "*", "*")]),
  65.             ([("WindowRef", "*", "OutMode")],    # Same, but other style headerfiles
  66.              [("ExistingWindowPtr", "*", "*")]),
  67.             
  68.             ([("WindowPtr", "FrontWindow", "ReturnMode")],
  69.              [("ExistingWindowPtr", "*", "*")]),
  70.             ([("WindowRef", "FrontWindow", "ReturnMode")],    # Ditto
  71.              [("ExistingWindowPtr", "*", "*")]),
  72.             ]
  73.  
  74. if __name__ == "__main__":
  75.     main()
  76.  
  77.